package acwing.动态规划;

import java.util.Scanner;

/**
 * 数字三角形
 *
 * @author yang
 * @date 2021/12/16
 */
public class 数字三角形 {

    static int N = 105;
    static int a[][] = new int[N][N];
    static int f[][] = new int[N][N];

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        for (int i = 1; i <= n; i++) f[n][i] = a[n][i];
        for (int i = n - 1; i > 0; i--) {
            for (int j = 1; j <= i; j++) {
                f[i][j] = Math.max(f[i + 1][j] + f[i][j],f[i + 1][j + 1] + f[i][j]);
            }
        }
        System.out.println(f[1][1]);
    }
}
